
package com.jf.cloud.live.controller.multishop;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.live.dto.LiveProdLogDTO;
import com.jf.cloud.live.model.LiveProdLog;
import com.jf.cloud.live.service.LiveProdLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 直播商品审核日志
 *
 * @author zz
 * @date 2022-08-17 17:09:06
 */
@RestController("multishopLiveProdLogController")
@RequestMapping("/m/live_prod_log")
@Tag(name = "直播商品审核日志")
public class LiveProdLogController {

    @Autowired
    private LiveProdLogService liveProdLogService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取直播商品审核日志列表" , description = "分页获取直播商品审核日志列表")
    public ServerResponseEntity<PageVO<LiveProdLog>> page(@Valid PageDTO pageDTO) {
        PageVO<LiveProdLog> liveProdLogPage = liveProdLogService.page(pageDTO);
        return ServerResponseEntity.success(liveProdLogPage);
    }

    @GetMapping("/info/{liveProdLogId}")
    @Operation(summary = "获取直播商品审核日志" , description = "根据liveProdLogId获取直播商品审核日志")
    public ServerResponseEntity<LiveProdLog> getByLiveProdLogId(@ParameterObject @RequestParam Long liveProdLogId) {
        return ServerResponseEntity.success(liveProdLogService.getByLiveProdLogId(liveProdLogId));
    }

    @PostMapping
    @Operation(summary = "保存直播商品审核日志" , description = "保存直播商品审核日志")
    public ServerResponseEntity<Void> save(@Valid @RequestBody LiveProdLogDTO liveProdLogDTO) {
        LiveProdLog liveProdLog = mapperFacade.map(liveProdLogDTO, LiveProdLog.class);
        liveProdLog.setLiveProdLogId(null);
        liveProdLogService.save(liveProdLog);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新直播商品审核日志" , description = "更新直播商品审核日志")
    public ServerResponseEntity<Void> update(@Valid @RequestBody LiveProdLogDTO liveProdLogDTO) {
        LiveProdLog liveProdLog = mapperFacade.map(liveProdLogDTO, LiveProdLog.class);
        liveProdLogService.update(liveProdLog);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除直播商品审核日志" , description = "根据直播商品审核日志id删除直播商品审核日志")
    public ServerResponseEntity<Void> delete(@RequestParam Long liveProdLogId) {
        liveProdLogService.deleteById(liveProdLogId);
        return ServerResponseEntity.success();
    }
}
